from sklearn import datasets
from sklearn.linear_model import LogisticRegression
import numpy as np
from sklearn.multiclass import OneVsRestClassifier
from sklearn.preprocessing import scale

# 多分类
data = datasets.load_iris()

X = scale(data.data[:, :])
y = data.target
lr = OneVsRestClassifier(LogisticRegression(C=1000, solver='sag', max_iter=1000))
lr.fit(X, y)
X_new = np.linspace(X.min(), X.max(), 1004).reshape(-1, 4)

p_proba = lr.predict_proba(X_new)
p = lr.predict(X_new)
print("预测概率:\n", p_proba[:5])  # 打印前5个样本
print("预测类别:", p[:5])
